{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Divide Array Into Equal Pairs"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #bit-manipulation #array #hash-table #counting"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #位运算 #数组 #哈希表 #计数"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: divideArray"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #将数组划分成相等数对"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个整数数组&nbsp;<code>nums</code>&nbsp;，它包含&nbsp;<code>2 * n</code>&nbsp;个整数。</p>\n",
    "\n",
    "<p>你需要将&nbsp;<code>nums</code> 划分成&nbsp;<code>n</code>&nbsp;个数对，满足：</p>\n",
    "\n",
    "<ul>\n",
    "\t<li>每个元素 <strong>只属于一个 </strong>数对。</li>\n",
    "\t<li>同一数对中的元素 <strong>相等</strong>&nbsp;。</li>\n",
    "</ul>\n",
    "\n",
    "<p>如果可以将 <code>nums</code>&nbsp;划分成 <code>n</code>&nbsp;个数对，请你返回 <code>true</code>&nbsp;，否则返回 <code>false</code>&nbsp;。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<b>输入：</b>nums = [3,2,3,2,2,2]\n",
    "<b>输出：</b>true\n",
    "<b>解释：</b>\n",
    "nums<code>&nbsp;中总共有 6 个元素，所以它们应该被划分成</code> 6 / 2 = 3 个数对。\n",
    "nums 可以划分成 (2, 2) ，(3, 3) 和 (2, 2) ，满足所有要求。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<b>输入：</b>nums = [1,2,3,4]\n",
    "<b>输出：</b>false\n",
    "<b>解释：</b>\n",
    "无法将 nums 划分成 4 / 2 = 2 个数对且满足所有要求。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>nums.length == 2 * n</code></li>\n",
    "\t<li><code>1 &lt;= n &lt;= 500</code></li>\n",
    "\t<li><code>1 &lt;= nums[i] &lt;= 500</code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [divide-array-into-equal-pairs](https://leetcode.cn/problems/divide-array-into-equal-pairs/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [divide-array-into-equal-pairs](https://leetcode.cn/problems/divide-array-into-equal-pairs/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['[3,2,3,2,2,2]', '[1,2,3,4]']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        c = Counter(nums)\n",
    "        for v in c.values():\n",
    "            if v % 2 != 0:\n",
    "                return False\n",
    "\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        lst=[0]*501\n",
    "        for i in range(len(nums)):\n",
    "            lst[nums[i]]+=1\n",
    "        for i in range(len(lst)):\n",
    "            if lst[i]%2==1:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        num_count = Counter(nums)\n",
    "        for key, value in num_count.items():\n",
    "            if value % 2 != 0:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        return all(v % 2 == 0 for v in Counter(nums).values())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        dic = {}\n",
    "        for i in nums:\n",
    "            if i in dic:\n",
    "                dic[i] += 1\n",
    "            else:\n",
    "                dic[i] = 1\n",
    "        for j in dic:\n",
    "            if dic[j] & 1 :\n",
    "                return False\n",
    "           \n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        num_count = {}\n",
    "        for ni in nums:\n",
    "            if ni not in num_count:\n",
    "                num_count[ni] = 0\n",
    "            num_count[ni] += 1\n",
    "        return all(freq%2==0 for freq in num_count.values())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        if len(nums)%2 != 0:\n",
    "            return False\n",
    "        nums.sort()\n",
    "        for i in nums:\n",
    "            if nums.count(i)%2 != 0:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        m = {}\n",
    "        for num in nums:\n",
    "            if num not in m.keys():\n",
    "                m[num] = 1\n",
    "            else:\n",
    "                m[num] += 1\n",
    "        for num, cnt in m.items():\n",
    "            if cnt % 2 != 0:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        cnt=Counter(nums)\n",
    "        for c in cnt:\n",
    "            if cnt[c]%2==1:\n",
    "                return False\n",
    "        \n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        n = len(nums)\n",
    "        dct = Counter(nums)     # counter计数器\n",
    "        return all(val % 2 == 0 for val in dct.values())   # 装有判断结果的生成器"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        freq = Counter(nums)   # 元素出现次数哈希表\n",
    "        return all(f % 2 == 0 for f in freq.values())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        mset = set()\n",
    "        for itm in nums:\n",
    "            if itm in mset:\n",
    "                mset.remove(itm)\n",
    "            else:\n",
    "                mset.add(itm)\n",
    "        return len(mset) == 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        counter = Counter(nums)\n",
    "        for v in counter.values():\n",
    "            if v % 2 != 0:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        counter = Counter(nums)\n",
    "        for v in counter.values():\n",
    "            if v % 2 != 0:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        dist = defaultdict(int)\n",
    "        for item in nums:\n",
    "            dist[item] +=1\n",
    "        for value in dist.values():\n",
    "            if value%2!=0:\n",
    "                return False\n",
    "        return True  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        cnt = Counter(nums)\n",
    "        return all(f % 2 == 0 for f in cnt.values())\n",
    "        # for k,v in cnt.items():\n",
    "        #     if v % 2:\n",
    "        #         return False\n",
    "        # return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        rec = {}\n",
    "        for num in nums:\n",
    "            if num in rec:\n",
    "                rec[num] += 1\n",
    "            else:\n",
    "                rec[num] = 1\n",
    "        for val in rec.values():\n",
    "            if val % 2 == 1:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        n = len(nums)\n",
    "        if n % 2 != 0:\n",
    "            return False\n",
    "        dct = Counter(nums)     # counter计数器\n",
    "        return all(val % 2 == 0 for val in dct.values())   # 装有判断结果的生成器"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        n = len(nums) // 2\n",
    "        isSingle = [False] * 501\n",
    "        for num in nums:\n",
    "            isSingle[num] = not isSingle[num]\n",
    "        for flag in isSingle:\n",
    "            if flag:\n",
    "                return False\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        count = Counter(nums)\n",
    "        return all(value % 2 == 0 for value in count.values())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        d = self.count(nums)\n",
    "        for v in d.values():\n",
    "            if v & 1 == 1:\n",
    "                return False\n",
    "        return True\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "    def count(self, nums: List[int]) -> dict:\n",
    "        d = {}\n",
    "        for num in nums:\n",
    "            if num not in d.keys():\n",
    "                d[num] = 1\n",
    "            else:\n",
    "                d[num] += 1\n",
    "        return d"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        my_dic=collections.Counter(nums)\n",
    "        for i in my_dic.values():\n",
    "            if i%2==1:\n",
    "                return False\n",
    "        return True\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from collections import Counter\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        ds = Counter(nums)\n",
    "        for _,v in ds.items():\n",
    "            if v % 2:\n",
    "                return False\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        freq = Counter(nums)   # 元素出现次数哈希表\n",
    "        return all(f % 2 == 0 for f in freq.values())\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        nums.sort()\n",
    "\n",
    "        for i in range(0, len(nums) - 1, 2):\n",
    "            if nums[i] != nums[i + 1]:\n",
    "                return False\n",
    "\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        arr = [0] * 501\n",
    "        for i in nums:\n",
    "            arr[i] += 1\n",
    "\n",
    "        for i in arr:\n",
    "            if i & 1:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        ad={}\n",
    "        for i in nums:\n",
    "            ad[i]=ad.get(i,0)+1\n",
    "        r=[v for v in ad.values() if v%2==1]\n",
    "        if r:\n",
    "            return False\n",
    "        else:\n",
    "            return True\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        a = Counter(nums)\n",
    "        for v in a.values():\n",
    "            if v%2:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        my_dic=collections.Counter(nums)\n",
    "        for i in my_dic.values():\n",
    "            if i%2==1:\n",
    "                return False\n",
    "        return True\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        c = Counter(nums)\n",
    "        return not any(v & 1 for v in c.values())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        return all(x%2==0 for x in Counter(nums).values())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        dic = {}\n",
    "\n",
    "        for i in nums:\n",
    "            dic[i] = dic.get(i, 0) + 1\n",
    "        \n",
    "        for v in dic.values():\n",
    "            if v % 2 != 0:\n",
    "                return False\n",
    "        \n",
    "        return True\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        ans = collections.defaultdict(int)\n",
    "        for x in nums:\n",
    "            ans[x] += 1\n",
    "        for x in ans.values():\n",
    "            if x & 1:\n",
    "                return False\n",
    "        return True\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        n = len(nums)\n",
    "        if n % 2 != 0:\n",
    "            return False\n",
    "        nums.sort()\n",
    "        for i in range(0,n,2):\n",
    "            if nums[i] != nums[i+1]:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        # 所有数字的个数都偶数\n",
    "        n = len(nums)\n",
    "        counter = collections.Counter(nums)\n",
    "        for k, v in counter.items():\n",
    "            if v % 2 == 1:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        for k, v in Counter(nums).items() :\n",
    "            if v % 2 :\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        cnt = Counter(nums)\n",
    "        for k,v in cnt.items():\n",
    "            if v % 2:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        for x in set(nums):\n",
    "            if nums.count(x) % 2:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        m = Counter(nums)\n",
    "        return all(m[k] % 2 == 0 for k in m)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        d = {}\n",
    "        for i in nums:\n",
    "            if not d.get(i, False):\n",
    "                d[i] = 1\n",
    "            else:\n",
    "                d[i] += 1\n",
    "        for k in d:\n",
    "            if d[k] % 2 != 0:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        count=Counter(nums)\n",
    "        return all(c % 2 == 0 for c in count.values())\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        nums.sort()\n",
    "        n = len(nums) // 2\n",
    "        for i in range(n):\n",
    "            if nums[i * 2] != nums[i * 2 + 1]:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        d = {}\n",
    "        for num in nums:\n",
    "            if num in d:\n",
    "                d[num] += 1\n",
    "            else:\n",
    "                d[num] = 1\n",
    "        \n",
    "        for k,v in d.items():\n",
    "            if v % 2 == 1:\n",
    "                return False\n",
    "        \n",
    "        return True\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        a = Counter(nums)\n",
    "        for j in a.values():\n",
    "            if j % 2 == 1:\n",
    "                return False\n",
    "        return True\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        set1 = set(nums)\n",
    "        for i in set1:\n",
    "            count = nums.count(i)\n",
    "            if count % 2:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        for x in set(nums):\n",
    "            if nums.count(x) % 2 == 0:\n",
    "                pass\n",
    "            else:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        hashtable = dict()\n",
    "        res = 0\n",
    "        for i in nums:\n",
    "            if i not in hashtable:\n",
    "                hashtable[i] = 1\n",
    "            else:\n",
    "                hashtable[i] += 1\n",
    "        \n",
    "        for value in hashtable.values():\n",
    "            if value & 1:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from collections import Counter\n",
    "class Solution:\n",
    "    def divideArray(self, nums: list[int]) -> bool:\n",
    "        freq = Counter(nums) #哈希表\n",
    "        return all(f % 2 == 0 for f in freq.values())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        fre = Counter(nums)\n",
    "        return all(f % 2==0 for f in fre.values())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        counter=Counter(nums)\n",
    "        if len(counter)>len(nums)/2:\n",
    "            return False\n",
    "        for v in counter.values():\n",
    "            if v%2!=0:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        freq = Counter(nums)   # 元素出现次数哈希表\n",
    "        return all(f % 2 == 0 for f in freq.values())\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        freq = Counter(nums)   # 元素出现次数哈希表\n",
    "        return all(f % 2 == 0 for f in freq.values())\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        return all([x % 2 == 0 for x in Counter(nums).values()])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        d = dict()\n",
    "        for i in nums:\n",
    "            d[i] = d.get(i, 0) + 1\n",
    "        return all(not (i & 1) for i in d.values())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        nums.sort()\n",
    "        for i in range(1, len(nums), 2):\n",
    "            if nums[i] != nums[i - 1]:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    def divideArray(self, nums: List[int]) -> bool:\r\n",
    "        records = {}\r\n",
    "        for num in nums:\r\n",
    "            records[num] = records.get(num, 0) + 1\r\n",
    "        \r\n",
    "        return all(x % 2 == 0 for x in records.values())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        from collections import Counter\n",
    "        cnt = Counter(nums)\n",
    "        for v in cnt.values():\n",
    "            if v%2 == 1:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        hh=[0]*501\n",
    "        a=0\n",
    "        for n in nums:\n",
    "            hh[n]+=1\n",
    "        for i in range(501):\n",
    "            if hh[i]%2==0:\n",
    "                a+=0\n",
    "            else:\n",
    "                a+=1\n",
    "        if a==0:\n",
    "            return True\n",
    "        else:\n",
    "            return False\n",
    "                \n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        cnt = Counter(nums)\n",
    "        return all(v % 2 == 0 for v in cnt.values())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        d = Counter(nums)\n",
    "        for v in d.values():\n",
    "            if v%2!=0:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        return not any([v%2 == 1 for v in Counter(nums).values()])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        count = [0] * 501\n",
    "        for num in nums:\n",
    "            count[num] += 1\n",
    "        for num in count:\n",
    "            if num % 2 != 0:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        nums.sort()\n",
    "        for i in range(0,len(nums),2):\n",
    "            if nums[i] != nums[i+1]:\n",
    "                return False\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        freq = Counter(nums)\n",
    "        return all(f%2==0 for f in freq.values())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        num = list(set(nums))\n",
    "        for i in num:\n",
    "            if nums.count(i) % 2 != 0:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        cnt = Counter(nums)\n",
    "        return all(va%2==0 for va in cnt.values())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        return sum(val % 2 > 0  for key,val in Counter(nums).items()) == 0\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from typing import List\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        hash = [0]*501\n",
    "        for num in nums:\n",
    "            hash[num] += 1\n",
    "        for i in range(501):\n",
    "            if hash[i] % 2 == 1:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        freq = Counter(nums)   # 元素出现次数哈希表\n",
    "        return all(f % 2 == 0 for f in freq.values())\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        ans = [0] * 501\n",
    "        for x in nums:\n",
    "            ans[x] ^= 1\n",
    "        return sum(ans) == 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from collections import Counter\n",
    "from typing import List\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        # 使用Counter来计算nums中每个数字的频率\n",
    "        counts = Counter(nums)\n",
    "\n",
    "        # 遍历字典中的每个键值对\n",
    "        for num, freq in counts.items():\n",
    "            # 如果任何数字的计数不是偶数，返回False\n",
    "            if freq % 2 != 0:\n",
    "                return False\n",
    "\n",
    "        # 否则，返回True\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        fre = Counter(nums)\n",
    "        return all(f % 2==0 for f in fre.values())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        for i in nums:\n",
    "            if nums.count(i) % 2 != 0:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        n = len(nums)\n",
    "        nums.sort()\n",
    "        for i in range(0, n, 2):\n",
    "            if nums[i] != nums[i + 1]:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        return sum(val % 2 > 0  for key,val in Counter(nums).items()) == 0\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        a=set(nums)\n",
    "        for num in a:\n",
    "            if nums.count(num)%2!=0:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def divideArray(self, nums: List[int]) -> bool:\n",
    "        s = set(nums)\n",
    "        for i in s:\n",
    "            if nums.count(i)%2 != 0:\n",
    "                return False\n",
    "        return True"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
